package com.yuedou.api.service.wxuser.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuedou.api.dao.wxuser.UserMpMapper;
import com.yuedou.api.entity.wxuser.User;
import com.yuedou.api.entity.wxuser.UserMp;
import com.yuedou.api.service.base.impl.BaseServiceImpl;
import com.yuedou.api.service.wxuser.UserMpService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserMpServiceImpl extends BaseServiceImpl<UserMpMapper, UserMp> implements UserMpService {

    @Resource
    private UserMpMapper userMpMapper;

    @Override
    public UserMp getLastUserMp() {
        QueryWrapper<UserMp> qw = new QueryWrapper<>();
        qw.orderByDesc("id");
        qw.last("limit 1");
        return userMpMapper.selectOne(qw);
    }


    @Override
    public UserMp getUserMp(User user) {
        QueryWrapper<UserMp> qw = new QueryWrapper<>();
        qw.eq("union_id",user.getUnionId());
        qw.last("limit 1");
        return userMpMapper.selectOne(qw);
    }

    @Override
    public List<UserMp> selectUserMpList(Integer merId) {
        return userMpMapper.selectUserMpList(merId);
    }
}
